package com.java1234.dao;

import java.sql.SQLException;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.ResultSetHandler;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.springframework.stereotype.Service;

import com.java1234.model.User;
import com.java1234.util.JdbcUtil;
@Service("userDao")
public class UserDao {

	public User login(User user) throws SQLException {

		QueryRunner qr = new QueryRunner(JdbcUtil.getDataSource());
		String sql = "select * from  user where username=?";

		
		ResultSetHandler<User> rsh = new BeanHandler<User>(User.class);
		User result = qr.query(sql, rsh, user.getUserName());
		return result;

	}


	public int update(User user) throws SQLException {
		//System.out.println(user.getPassword());
		QueryRunner qr = new QueryRunner(JdbcUtil.getDataSource());
		String sql = "update  user set userName=? , password=? where id=?";
		int result = qr.update(sql, user.getUserName(),user.getPassword(),user.getId());
		return result;
		
	}

}
